<?php
class Admin_GroupController extends Zend_Controller_Action
{
	private $t;
	private $hash;

	public function preDispatch()
	{
		$this->t = Zend_Registry::get('Zend_Translate');
		$this->view->t = $this->t;
	}

	public function listAction() {
		$this->view->title = $this->t->_('all groups');
		$groups = new Groups();
		$this->view->groups = $groups->fetchAll();
	}

	public function saveAction()
	{
		$form = new GroupForm();

		$this->view->title = $this->t->_('save group');
		$this->view->form = $form;

		$id = (int) $this->_request->getParam('id');

		$groups = new Groups();

		$group = $groups->fetchRow("`id` = '{$id}'");

		if($group == NULL) {
			$group = $groups->createRow();
		}

		if($this->_request->isPost()) {
			$formData = $this->_request->getPost();
			if($form->isValid($formData)) {
				$group->name = $form->getValue('name');

				$group->save();
			}
		} else {
			$form->populate($group->toArray());
		}
	}

	public function deleteAction()
	{

	}
}